package com.axjy.action;

import com.axjy.pojo.User;
import com.axjy.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * Created by l on 2018/1/9.
 */
@Controller
@RequestMapping("/sys")
public class SystemHandler {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public String login(String userCode, String userPassword, HttpSession session){
        User loginUser=userService.login(userCode,userPassword);
        if(loginUser==null){
            throw new RuntimeException("用户名或者密码错误！");
        }
        session.setAttribute("loginUser",loginUser);
        return "redirect:/index";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/login.jsp";
    }
}
